<?php

require("../../vendors/simpletest/autorun.php");
require("db_dao_base.php");

class DbDaoBaseTest extends UnitTestCase{
	
	function test_dorp_table(){
		DbDaoBase::dorp_table("users");
		DbDaoBase::dorp_table("users_random");
		//print "pass";
		//$this->assertEqual(1 , 1);
	}
	
	function test_create_table(){
		$tablename = "users";
		$sql = "(`id` INTEGER PRIMARY KEY,  `opt_lock` INTEGER,  `create_time` datetime  , 'login_name' varchar(64) NOT NULL , `password` varchar(128) NOT NULL)";
		DbDaoBase::create_table($tablename , $sql);
		//print "pass";
		//DbDaoBase::dorp_table($tablename);
		//$this->assertEqual(1 , 1);
	}
	
	
	function test_insert(){
		$tablename = "users";
		$userid = 132;
		$login_name = "test_user";
		$password = "123123";
		$values = array("id" => $userid , "login_name" => $login_name , "password" => $password);
		DbDaoBase::insert($tablename , $values);
		//DbFactory::get_instance()->query("")
		$value = DbFactory::get_instance()->query("select * from $tablename");
		foreach($value as $row){
			$this->assertEqual($row["id"] , $userid);
			$this->assertEqual($row["login_name"] , $login_name);
			$this->assertEqual($row["password"] , $password);
		}
	}
}
?>